var t = require("../../@babel/runtime/helpers/toConsumableArray"), a = getApp().globalData.api;

getApp();

Page({
    data: {
        options: {},
        loadingExit: !1,
        isReload: !1,
        lastAreaCode: getApp().globalData.selectedCityAreaCode,
        showfilter: !1,
        showfilterindex: null,
        classArray: [],
        screeningArray: [],
        listData: null,
        tagsList: [],
        filterList: [],
        searchValue: "",
        dateTime: "日期",
        topNum: 0,
        branchDataList: null,
        showBranch: !1,
        redEnvelopeList: [],
        gdt_vid: null,
        originUnitParam: null,
        ifShowShartBtn: getApp().globalData.ifSharebtn,
        h5Url: ""
    },
    onLoad: function(t) {
        console.log(t, "hospital-list"), this.setData({
            options: t
        });
        var a = t.originUnitParam, e = t.gdt_vid;
        e && (getApp().globalData.gdt_vid = e, this.setData({
            gdt_vid: e
        })), a && this.setData({
            originUnitParam: a
        });
        var i = this;
        this.setData({
            searchCity: getApp().globalData.selectedCity
        }), this.loadData(), getApp().globalData.isFirstLoacation && getApp().firstLocation().then(function(t) {
            null != t && (getApp().globalData.isFirstLoacation = !1, t.city != getApp().globalData.selectedCity && i.getCityCode(t.province, t.city, t.latitude, t.longitude));
        }), this.getHeight();
    },
    shareBtn: function(t) {
        var a = t.originUnitParam;
        if (getApp().initShare(t), console.log(getApp().ifShowBtn(), wx.getStorageSync("token")), 
        getApp().ifShowBtn()) {
            this.setData({
                ifShowShartBtn: getApp().ifShowBtn()
            });
            var e = "".concat(getApp().globalData.selectedCityAreaCode, "/ul");
            this.setData({
                h5Url: getApp().getDisUrl(e, {
                    originUnitParam: a || null
                })
            }), console.log(this.data.h5Url);
        }
    },
    onPkgShareClick: function() {
        var t = this.selectComponent("#shareAlert");
        console.log(t), t.onPkgShareClick();
    },
    getHeight: function() {
        var t = this;
        wx.getSystemInfo({
            success: function(a) {
                var e = a.windowHeight;
                t.setData({
                    clientHeight: e
                });
            }
        });
    },
    getCityCode: function(t, e, i, s) {
        var o = this, l = {
            province: t,
            city: e
        };
        a.post1("wechat/home/getlocalcityinfo", l, !1).then(function(t) {
            if ("1" == t.code) {
                var a = t.data.areacode;
                getApp().globalData.localCity = e, getApp().globalData.localCityAreaCode = a, getApp().globalData.localLatitude = i, 
                getApp().globalData.localLongitude = s, getApp().globalData.selectedCity = e, getApp().globalData.selectedCityAreaCode = a, 
                o.setData({
                    searchCity: getApp().globalData.selectedCity
                }), o.loadData();
            }
        }, function(t) {});
    },
    loadData: function() {
        this.getRequestHospitalList(1);
    },
    loadMoreData: function() {
        this.data.loadingExit || this.getRequestHospitalList(this.data.listData.pageNum + 1);
    },
    getRequestHospitalList: function(e) {
        var i = this, s = "", o = "";
        0 == i.data.isReload ? 1 == getApp().globalData.jumpHospitalList.isJumpHospitalList ? (s = getApp().globalData.jumpHospitalList.requestParamsUrl, 
        i.setData({
            searchValue: "",
            dateTime: "日期"
        })) : (i.data.screeningArray.forEach(function(t, a) {
            i.data.filterList.forEach(function(a, e) {
                t.type == a.type && (a.selectId = t.selectId);
            });
        }), i.data.filterList.forEach(function(t, a) {
            0 != t.selectId && t.microCriteriaDTOList.forEach(function(a, e) {
                a.id == t.selectId && ("6B01" == a.type ? o = a.code : s += a.code);
            });
        })) : i.setData({
            isReload: !1
        });

        let searchModel1= {
            areacode: getApp().globalData.selectedCityAreaCode,
            clientType: 2,
            lat: getApp().globalData.localLatitude || "",
            lon: getApp().globalData.localLongitude || "",
            oriFutureDate: i.data.checkDate ? i.data.checkDate : "",
            name: 0 != i.data.searchValue.length ? i.data.searchValue : "",
            originUnitParam: s,
            oriOrderBy: o
        }
        var para = {
            pageNum: e,
            pageSize: 10,
            searchModel: JSON.stringify(searchModel1) 
        };
        this.data.originUnitParam && (l.searchModel.originUnitParam = this.data.originUnitParam), 
        null != this.data.gdt_vid && (l.searchModel.clickId = this.data.gdt_vid), a.post1("/wechat/home/_listMicroHospital", para, !i.data.values).then(function(a) {
            if ("1" == a.code) {
                var e = i.data.listData;
                1 == a.data.pageNum ? (i.goTop(), e = a.data) : (e.list = [].concat(t(i.data.listData.list), t(a.data.list)), 
                e.pageNum = a.data.pageNum, e.total = a.data.total, e.microBottomCriteriaListDTOS = a.data.microBottomCriteriaListDTOS, 
                e.microCriteriaListDTOS = a.data.microCriteriaListDTOS), i.setData({
                    loadingExit: e.list.length >= a.data.total,
                    listData: e,
                    tagsList: a.data.microBottomCriteriaListDTOS,
                    filterList: a.data.microCriteriaListDTOS,
                    values: a.data
                }), 1 == getApp().globalData.jumpHospitalList.isJumpHospitalList && (getApp().globalData.jumpHospitalList.isJumpHospitalList = !1, 
                getApp().globalData.jumpHospitalList.requestParamsUrl = ""), i.checkFilterData(), 
                wx.setNavigationBarTitle({
                    title: "体检网"
                });
            }
        }, function(t) {});
    },
    checkFilterData: function() {
        var t = [], a = [], e = 0;
        this.data.filterList.forEach(function(i, s) {
            if (e < 3 && ("6B01" == i.type || "6B02" == i.type || "6B03" == i.type)) {
                var o = {
                    id: 0,
                    code: null,
                    name: "不限",
                    type: i.type,
                    value: null,
                    isShowBottom: !1,
                    orderBy: null,
                    classify: null,
                    showBottomOrderBy: null
                };
                "6B01" == i.type && (i.typeName = "推荐排序", o.name = "推荐排序");
                var l = i.microCriteriaDTOList;
                0 != l.length && l.unshift(o), 0 != i.selectId && l.forEach(function(t, a) {
                    i.selectId == t.id && (i.selectName = t.name);
                }), t.push(i), e += 1;
            } else i.showMore = !1, "6B07" != i.type && "6B08" != i.type && (i.microCriteriaDTOList = i.microCriteriaDTOList.filter(function(t) {
                if (t.ifShow) return t;
            }), a.push(i));
        });
        var i = this.data.tagsList;
        this.data.filterList.forEach(function(t, a) {
            0 != t.selectId && i.forEach(function(a, e) {
                t.selectId == a.id && t.type == a.type && (a.isSelect = 1);
            });
        }), this.setData({
            classArray: t,
            screeningArray: a,
            tagsList: i
        });
    },
    getHospitalBranchDat: function(t, e, i) {
        if (t || e) {
            var s = this, o = {
                pageNum: 1,
                pageSize: 50,
                searchModel: {
                    areaCode: t,
                    name: null,
                    hospitalGroupId: e
                }
            };
            a.postPort("listMicroBrandHospitalList", o, !1).then(function(t) {
                if ("SUCCESS" == t.result) {
                    var a = [];
                    t.values.list.forEach(function(t, e) {
                        t.id != i && a.push(t);
                    }), s.setData({
                        branchDataList: a,
                        showBranch: !0
                    });
                }
            }, function(t) {
                t.data.hasOwnProperty("result") && "ERROR" == t.data.result && wx.showToast({
                    title: t.data.message[0].message,
                    icon: "none",
                    duration: 2e3,
                    mask: !0
                });
            });
        }
    },
    searchTap: function() {
        wx.navigateTo({
            url: "/pages/hospital-list/hopital-search/hopital-search"
        });
    },
    cityListTap: function() {
        wx.navigateTo({
            url: "/pages/city/city-list"
        });
    },
    dataTimeShow: function() {
        this.selectComponent("#dataList").powerDrawer();
    },
    atTime: function(t) {
        this.setData({
            dateTime: 0 == t.detail ? "日期" : t.detail.length > 5 ? t.detail.substring(5) : "日期",
            checkDate: t.detail
        }), this.loadData();
    },
    setFilterPanel: function(t) {
        this.data;
        var a = t.currentTarget.dataset.findex, e = this.data.showfilterindex, i = this.data.showfilter;
        this.setData({
            showfilter: e != a || !i,
            showfilterindex: e == a ? null : a
        });
    },
    itemClassTap: function(t) {
        var a = t.currentTarget.dataset.iteminfo;
        this.hideFilter();
        var e = this.data.filterList;
        e.forEach(function(t, e) {
            t.type == a.type && (t.selectId = a.id);
        }), this.setData({
            filterList: e
        }), this.loadData();
    },
    rightTabMoreTap: function(t) {
        var a = t.currentTarget.dataset.idx, e = this.data.screeningArray;
        e.forEach(function(t, e) {
            a == e && (t.showMore = !t.showMore);
        }), this.setData({
            screeningArray: e
        });
    },
    rightTabMenuItemTap: function(t) {
        var a = t.currentTarget.dataset.iteminfo, e = this.data.screeningArray;
        e.forEach(function(t, e) {
            a.type == t.type && (t.selectId == a.id ? t.selectId = 0 : t.selectId = a.id);
        }), this.setData({
            screeningArray: e
        });
    },
    hideFilter: function() {
        this.setData({
            showfilter: !1,
            showfilterindex: null
        });
    },
    tagsTap: function(t) {
        var a = t.currentTarget.dataset.taginfo, e = this.data.filterList;
        e.forEach(function(t, e) {
            t.type == a.type && (0 == t.selectId || t.selectId != a.id ? t.selectId = a.id : t.selectId = 0);
        }), this.setData({
            filterList: e
        }), this.loadData();
    },
    cleanTap: function() {
        var t = this.data.screeningArray;
        t.forEach(function(t, a) {
            t.selectId = 0;
        }), this.setData({
            screeningArray: t
        });
    },
    sureTap: function() {
        this.hideFilter(), this.loadData();
    },
    hospitalDetailTap: function(t) {
        var a = t.currentTarget.dataset.info, e = a.domain, i = a.areacode;
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(e, "&areacode=").concat(i)
        });
    },
    hostpitalPackageTap: function(t) {
        var a = t.currentTarget.dataset.info;
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(a.domain, "&areaCode=").concat(a.areaCode, "&selectPkgId=").concat(a.id)
        });
    },
    branchTap: function(t) {
        var a = "/pages/hospitalinfo/hospitalinfo?domain=".concat(t.currentTarget.dataset.info.domain, "&areaCode=").concat(t.currentTarget.dataset.info.areaCode);
        wx.navigateTo({
            url: a
        });
    },
    hospitalBranchTap: function(t) {
        var a = t.currentTarget.dataset.info;
        this.data.showBranch ? this.setData({
            showBranch: !1
        }) : this.getHospitalBranchDat(a.areaCode, a.groupId, a.id);
    },
    closeBranchTap: function() {
        this.setData({
            showBranch: !1
        });
    },
    upgradeTap: function(t) {
        this.setData({
            isReload: !0,
            searchValue: ""
        }), this.loadData();
    },
    scrollLoading: a.throttle(function(t) {
        t.loadMoreData();
    }, 800),
    onShow: function() {
        this.shareBtn(this.data.options), this.data.lastAreaCode != getApp().globalData.selectedCityAreaCode && (this.setData({
            searchCity: getApp().globalData.selectedCity,
            lastAreaCode: getApp().globalData.selectedCityAreaCode
        }), this.loadData()), this.setData({
            redEnvelopeList: getApp().globalData.redEnvelopeList
        });
    },
    shareEvent: function(t) {
        this.setData({
            showShare: t.detail.showShare
        });
    },
    goTop: function() {
        this.setData({
            topNum: 0
        });
    },
    onShareAppMessage: function() {
        var t = wx.getStorageSync("disCode"), a = {
            disCode: t = t || getApp().globalData.keyTjgj.disCode,
            originUnitParam: this.data.originUnitParam
        }, e = "";
        for (var i in a) a[i] && (e = e.length > 1 ? "".concat(e, "&").concat(i, "=").concat(a[i]) : "".concat(i, "=").concat(a[i]));
        var s = "/pages/hospital-list/hospital-list?".concat(e);
        return console.log(s, "onShareAppMessage"), {
            title: "点击查看您的体检方案",
            path: s,
            imageUrl: "/image/share/icon_share_cart_tj.jpg"
        };
    }
});